package com.j2203.controller;

import com.j2203.entity.GmUser;
import com.j2203.service.SendEmailService;
import com.j2203.service.UserService;
import com.j2203.vo.ResultMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.mail.MessagingException;

@RestController
public class UserRgstController {
    @Autowired
    private SendEmailService sendEmailService;
    @Autowired
    private UserService userService;
    //发送邮件
    @RequestMapping("/sendMail")
    private ResultMsg sendMail(String toMail) throws MessagingException {
        ResultMsg resultMsg = sendEmailService.sendMail(toMail);
        return resultMsg;
    }
//    注册
    @RequestMapping(value = "/userrgst",method = RequestMethod.POST)
    public ResultMsg userrgst(@RequestBody GmUser gmUser){
        ResultMsg resultMsg = userService.upDateOne(gmUser);
        return resultMsg;
    }
//登录

    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public ResultMsg login(@RequestBody GmUser gmUser){
        ResultMsg resultMsg = userService.findOneByMailAndPwd(gmUser.getEmail(),gmUser.getPassword());
        return resultMsg;
    }


}
